
{
module Lex_1 where
}

%wrapper "basic"

$digito      							= 0-9
$letra        							= [a-zA-Z]
$graphic    							= $printable # $white
@string    								= \" ($graphic # \")* \"

tokens :-

	($white # \n)*\n($white)*					{ \s -> TokenBreakLine}
	[$white # \n]+								;
	@string										{ \s -> TokenStringLiteral (init (tail s))}
	$digito+									{ \s -> TokenIntLiteral (read s)}
	"return"									{ \s -> TokenReturn}
	"int"										{ \s -> TokenInteger}
	"boolean"									{ \s -> TokenBoolean}
	
	"true"										{ \s -> TokenTrue}
	"false"										{ \s -> TokenFalse}
	
	[\+\-\*\/]									{ \s -> TokenOp (head s)}
	"<>"										{ \s -> TokenComp s}
	"><"										{ \s -> TokenComp s}
	">="										{ \s -> TokenComp s}
	"<="										{ \s -> TokenComp s}
	">"											{ \s -> TokenComp s}
	"<"											{ \s -> TokenComp s}
	"="											{ \s -> TokenAttr}
	
	"if"										{ \s -> TokenIf}
	"else"										{ \s -> TokenElse}
	"end"($white+)"if"							{ \s -> TokenEndIf}
	
	"for"										{ \s -> TokenFor}
	"to"										{ \s -> TokenTo}
	"exit"										{ \s -> TokenExit}
	"next"										{ \s -> TokenNext}	
	
	"do"										{ \s -> TokenDo}
	"while"										{ \s -> TokenWhile}
	"loop"										{ \s -> TokenLoop}
	"until"										{ \s -> TokenUntil}
	
	"function"									{ \s -> TokenFunction}
	"as"										{ \s -> TokenAs}
	"sub"										{ \s -> TokenSub}	
	
	"["											{ \s -> TokenColchLeft}
	"]"											{ \s -> TokenColchRight}
	"("											{ \s -> TokenParLeft}
	")"											{ \s -> TokenParRight}
	
	","											{ \s -> TokenComma}
	"input"										{ \s -> TokenInput}
	"print"										{ \s -> TokenPrint}
	"program"									{ \s -> TokenProgram}
	"end"										{ \s -> TokenEnd}
	
	$letra[$letra $digito \_ \']*				{ \s -> TokenId s}
{
-- Each action has type :: String -> Token

-- The token type:
data Token = 
	TokenBreakLine |
	TokenIntLiteral Int|
	TokenStringLiteral String|
	TokenId String|
	TokenReturn |
	TokenInteger |
	TokenBoolean |
	TokenTrue |
	TokenFalse |
	TokenOp Char |
	TokenComp String|
	TokenAttr|
	TokenIf |
	TokenElse |
	TokenEndIf |
	TokenFor |
	TokenTo |
	TokenExit |
	TokenNext |
	TokenDo |
	TokenWhile |
	TokenLoop |
	TokenUntil |
	TokenFunction |
	TokenAs |
	TokenSub |
	TokenColchLeft |
	TokenColchRight |
	TokenParLeft |
	TokenParRight |
	TokenComma |
	TokenInput |
	TokenPrint |
	TokenProgram |
	TokenEnd
	deriving (Eq,Show)

-- main = do
--  s <- getContents
--  print (alexScanTokens s)

}